<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button>添加</button>
    <button>获取</button>
    <button>删除</button>
    <button>清空</button>

    <script>
        var btns = document.querySelectorAll('button');
        btns[0].onclick = function() {
            sessionStorage.setItem('name', '老王');
            sessionStorage.setItem('age', '80');
            sessionStorage.setItem('sex', '男');
        }
        btns[1].onclick = function() {
            alert(sessionStorage.getItem('name'));
        }
        btns[2].onclick = function() {
            sessionStorage.removeItem('name');
        }
        btns[3].onclick = function() {
            sessionStorage.clear();
        }
    </script>
</body>
</html>